package kr.co.redcircle.service.oAuth;

import java.util.Scanner;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.FacebookApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

public class FacebookTestCase
{

  private static final String NETWORK_NAME = "Facebook";
  private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me";
  private static final Token EMPTY_TOKEN = null;

  public static void main(String[] args)
  {

	  String apiKey = "237156643066135";
	  String apiSecret = "2f1143905e8bd5e02dc497b6aa1dabb7";
	  String callback = "http://broker.inpion.com/ExampleBizBrokerWASClient/FacebookOAuth.jsp";
	  
	  OAuthService service = new ServiceBuilder().
    		provider(FacebookApi.class).
    		apiKey(apiKey).
    		apiSecret(apiSecret).
    		callback(callback).
    		build();
    
	  Scanner in = new Scanner(System.in);
	  String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
	  System.out.println(authorizationUrl);
	  System.out.print(">>");
	  Verifier verifier = new Verifier(in.nextLine());
	  Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
	  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
	  service.signRequest(accessToken, request);
	  Response response = request.send();
	  System.out.println();
	  System.out.println(response.getCode());
	  System.out.println(response.getBody());

  }
}